﻿#pragma once

#include <QObject>

#include "TurnTableCodec.h"

class LogSaver;

class TurnTableConnectionStateManager : public QObject
{
  Q_OBJECT

public:

private:
  TurnTableCodec::ConnectionState turnTableConnectionState = TurnTableCodec::State_Disconnected;//转台连接状态位
  TurnTableCodec::ConnectionState thermostatConnectionState = TurnTableCodec::State_Disconnected;//温箱连接状态位
  //计时器---------------------------------------------------------------------------------------------------------------------
  QTimer timer_turnTableConnectionTimeOut;//转台连接超时计时器
  QTimer timer_checkThermostatTemperature;//检查温箱温度计时器
  QTimer timer_checkTurnTableCurrentState;//检查转台现场数据计时器，即位置和速率
  QTimer timer_checkTurnTableRunningState;//检查转台运行状态计时器，即电源、电路、功放、运行四个状态。
  int interval_turnTableConnectionTimeOut = 1000;//转台连接超时计时器超时时间
  int interval_checkThermostatTemperature = 200;//检查温箱温度计时器超时时间
  int interval_checkTurnTableCurrentState = 100;//检查转台现场数据计时器超时时间
  int interval_checkTurnTableRunningState = 500;//检查转台运行状态计时器超时时间
  //----------------------------------------------------------------------------------------------------------------------------

  //需要用到的外部组件-------------------------------------------------------------------------------------------------------
  TurnTableCodec* turnTableCodec = Q_NULLPTR;//需要转台编码解码器来发送状态查询指令
  LogSaver* logSaver = Q_NULLPTR;
  //----------------------------------------------------------------------------------------------------------------------------

public:
  TurnTableConnectionStateManager(QObject* parent = Q_NULLPTR);
  ~TurnTableConnectionStateManager();
signals:
  void signal_turnTable_connectionTimeOut();
private slots:
  void slot_timer_turnTableConnectionTimeOut_timeOut();
  void slot_timer_checkThermostatTemperature_timeOut();
  void slot_timer_checkTurnTableCurrentState_timeOut();
  void slot_timer_checkTurnTableRunningState_timeOut();
  void slot_setTurnTableConnection(TurnTableCodec::ConnectionState connectionState);
  void slot_setThermostatConnection(TurnTableCodec::TurnTableInstructionFlag instructionFlag, float arg1, float arg2, float arg3);
  //geter and seter
public:
  TurnTableCodec::ConnectionState getTurnTableConnectionState();
  TurnTableCodec::ConnectionState getThermostatConnectionState();
  int getInterval_turnTableConnectionTimeOut();
  void setInterval_turnTableConnectionTimeOut(int interval_turnTableConnectionTimeOut);
  int getInterval_checkThermostatTemperature();
  void setInterval_checkThermostatTemperature(int interval_checkThermostatTemperature);
  int getInterval_checkTurnTableCurrentState();
  void setInterval_checkTurnTableCurrentState(int interval_checkTurnTableCurrentState);
  int getInterval_checkTurnTableRunningState();
  void setInterval_checkTurnTableRunningState(int interval_checkTurnTableRunningState);
  TurnTableCodec* getTurnTableCodec();
  void setTurnTableCodec(TurnTableCodec* turnTableCodec);
  LogSaver* getLogSaver();
  void setLogSaver(LogSaver* logSaver);
};
